package com.zzh.app.plugin.xhttputils;

import android.os.Build;


import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.http.common.util.LogUtil;
import org.xutils.http.request.params.RequestParams;

import java.util.Map;

/**
 * Created by ZZH on 2019-12-12.
 *
 * @Date: 2019-12-12
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 基本参数
 */
public class AppRequestParams extends RequestParams {

    private boolean showLoadingDialog = false;

    private boolean isAuth;

    public boolean isAuth() {
        return isAuth;
    }

    public void setAuth(boolean auth) {
        isAuth = auth;
    }

    public AppRequestParams() {
        setBodyContentType("application/json");
        initParams();
    }

    public AppRequestParams(boolean isAppSysParams) {
        setBodyContentType("application/json");
        if (isAppSysParams) {
            initParams();
        }
    }

    public AppRequestParams(String url) {
        super(url);
        setBodyContentType("application/json");
        initParams();
    }

    public AppRequestParams(String url, boolean isAppSysParams) {
        super(url);
        setBodyContentType("application/json");
        if (isAppSysParams) {
            initParams();
        }
    }

    private void initParams() {
        try {
            addParameter("zyOs", "Android");
            //手机系统版本号
            addParameter("zyOsVersion", Build.VERSION.RELEASE);
            //手机型号
            addParameter("zyModel", Build.MODEL);
            //手机厂商
            addParameter("zyBrand", Build.BRAND);
        } catch (Exception e) {
            LogUtil.e(e.getMessage());
        }
    }

    public boolean isShowLoadingDialog() {
        return showLoadingDialog;
    }

    public void setShowLoadingDialog(boolean showLoadingDialog) {
        this.showLoadingDialog = showLoadingDialog;
    }

    public AppRequestParams buildBodyContent(String content) {
        LogUtil.d("----params: " + content);
        setBodyContent(content);
        return this;
    }

    public AppRequestParams buildBodyContent(Map<String, Object> params) {
        try {
            JSONObject data = new JSONObject().putOpt("data", params);
            setBodyContent(data.toString());
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }


        return this;
    }
}
